#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc,char *argv[])
{
    if(argc == 3)
    {
        int fd1 = open(argv[1],O_RDONLY | O_CREAT,0644);
        int fd2 = open(argv[2],O_RDWR | O_CREAT,0771);
        char buffer[128] = {0};
        while(1)
        {
            int readBytes = read(fd1,buffer,sizeof(buffer) - 1);
            if((readBytes < sizeof(buffer) - 1) || readBytes == 0)
            {
                write(fd2,(void *)buffer,strlen(buffer));
                break;
            }
            write(fd2,(void *)buffer,strlen(buffer));
            memset(buffer,0,sizeof(buffer));
        }
        close(fd1);
        close(fd2);
    }
    else if(argc < 3)
        printf("Few argument expected.\n");
    else
        printf("Moer argument expected.\n");

    return 0;
}